﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using MpSoft.Library.BUSS.Customers;
using MpSoft.Library.DTO;

namespace MpSoft.Web.Controls.Customer
{
    public partial class PollResultControl : System.Web.UI.UserControl
    {
        #region Var
        #endregion

        #region Method

        protected string getAnswer()
        {
            var pollFirst = PollBUSS.Poll_List();
            var objPoll = pollFirst != null ? pollFirst.FirstOrDefault() : null;
            if (objPoll != null)
            {
                var listAnswer = PollAnswerBUSS.PollAnswer_ByPollID(objPoll.PollID);
                int totalAnswer = PollAnswerBUSS.PollAnswer_TotalCount(objPoll.PollID);
                StringBuilder sb = new StringBuilder();
                double percent = 0;
                sb.Append("<h3 class='pollName'>" + objPoll.Name + "</h3>"); ;
                sb.Append("<div class='pollAnswer'>");
                foreach (var obj in listAnswer)
                {
                    if (totalAnswer > 0)
                    {
                        percent = (double.Parse(obj.Count.ToString()) / double.Parse(totalAnswer.ToString())) * 100.0;
                        sb.Append("<i>" + obj.Name + "</i>");
                        sb.Append("<img src='/Images/bullet-a.png' style='width:" + percent.ToString().Replace(",", ".") + "%'/>");
                        sb.Append("<span>" + percent.ToString("0.0") + "%</span>");
                    }
                    else
                    {
                        sb.Append("<span>0%</span>");
                    }

                }
                sb.Append("</div>");
                return sb.ToString();
            }
            return "";
        }

        #endregion

        #region Event

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #endregion

        #region Properties
        #endregion
    }
}